﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace GMS.Dinasty.BO
{
    public class PropertieGood
    {
        public PropertieGood()
        { }
        private int _idGood;
        public int IdGood
        {
            get { return _idGood; }
            set { _idGood = value; }
        }
        private string _captionGood;
        public string CaptionGood
        {
            get { return _captionGood; }
            set { _captionGood = value; }
        }
    }
    public class Good
    {
        public Good()
        { }
        public Good(int typeGood)
        { }
        public Good(string allParameters)
        {
                List<string> vals = new List<string>();
                foreach (string s in allParameters.Split(';'))
                {
                    vals.Add(s);
                }
                if (vals.Count > 2)
                {
                    _idGood = int.Parse(vals[0]);
                    _caption = vals[1];
                    _groupGood = int.Parse(vals[2]);
                    if (_groupGood == 1)
                    {
                        if (vals.Count > 4)
                        {
                            _suffusion = vals[3];
                            _color = vals[4];
                        }
                        else
                        {
                            _suffusion = string.Empty;
                            _color = string.Empty;
                        }
                        for (int i = 5; i < vals.Count-1; i++)
                        {
                            string[] stringDims = vals[i].Split('x');
                            DimensionsA dim = new DimensionsA(int.Parse(stringDims[0]), int.Parse(stringDims[1]), int.Parse(stringDims[2]));
                            _dims.Add(dim);
                        }
                    }
                    else
                    {
                        if (vals.Count > 4)
                        {
                            _suffusion = vals[3];
                            _color = vals[4];
                        }
                        else
                        {
                            _suffusion = string.Empty;
                            _color = string.Empty;
                        }
                        if (vals.Count > 5)
                        {
                            string scan = vals[5];
                            foreach(string s in scan.Split('*'))
                            {
                                _scans.Add(s);
                            }
                        }
                        if (vals.Count > 6)
                        {
                            _lenght = int.Parse(vals[6]);
                        }
                    }
                }
                else
                {
                    _caption = vals[0];
                }
        }
        private List<string> _scans = new List<string>();
        public List<string> Scans
        {
            get { return _scans; }
            set { _scans = value; }
        }
        private int _lenght;
        public int Lenght
        {
            get { return _lenght; }
            set { _lenght = value; }
        }
        private int _idGood;
        public int IdGood
        {
            get { return _idGood;}
            set { _idGood = value; }
        }

        private string _caption;
        public string Caption
        {
            get { return _caption; }
            set { _caption = value; }
        }
        private int _groupGood;
        public int GroupGood
        {
            get { return _groupGood; }
            set { _groupGood = value; }
        }
        public override string ToString()
        {
            return _caption + " " + _suffusion + " " + _color;
        }
        private List<DimensionsA> _dims = new List<DimensionsA>();
        public List<DimensionsA> Dims
        {
            get { return _dims; }
            set { _dims = value; }
        }
        public string InputString()
        {
            string str = string.Empty;
            if (_groupGood == 1)
            {
                if (concatDims().Length != 0)
                    str = _idGood + ";" + _caption + ";" + _groupGood + ";" + _suffusion + ";" + _color + ";" + concatDims();
                else
                    str = _idGood + ";" + _caption + ";" + _groupGood + ";" + _suffusion + ";" + _color;
            }
            if (_groupGood == 2)
            {
                if (ConcatStrips().Length != 0)
                    str = _idGood + ";" + _caption + ";" + _groupGood + ";" + _suffusion + ";" + _color + ";" + ConcatStrips();
                else
                    str = _idGood + ";" + _caption + ";" + _groupGood + ";" + _suffusion + ";" + _color;
            }
            str = str + ";" + _lenght;
            return str;
        }
        private string ConcatStrips()
        {
            string str = string.Empty;
            for (int i = 0; i < _scans.Count; i++)
            {
                if (i != _scans.Count - 1)
                    str = str + _scans[i].ToString() + "*";
                else
                    str = str + _scans[i].ToString();
            }
            return str;
        }
        public void ChangeSuffusionColor(string Suffusion, string Color)
        {
            _suffusion = Suffusion;
            _color = Color;
        }
        private string _suffusion = string.Empty;
        public string Suffusion
        {
            get { return _suffusion; }
            set { _suffusion = value; }
        }
        private string _color = string.Empty;
        public string Color
        {
            get { return _color; }
            set { _color = value; }
        }
        private string concatDims()
        {
            string returnString = string.Empty;
            foreach (DimensionsA dim in _dims)
            {
                if (_dims.IndexOf(dim) == _dims.Count - 1)
                    returnString = returnString + dim._width + "x" + dim._height + "x" + dim._quantity;
                else
                    returnString = dim._width + "x" + dim._height + "x" + dim._quantity + ";" + returnString;
            }
            return returnString;
        }
        private string concatDimsForPrint()
        {
            string returnString = string.Empty;
            foreach (DimensionsA dim in _dims)
            {
                if (_dims.IndexOf(dim) == _dims.Count - 1)
                    returnString = returnString + dim._width + " x " + dim._height + " x " + dim._quantity;
                else
                    returnString = dim._width + " x " + dim._height + " x " + dim._quantity + "\r\n" + returnString;
            }
            return returnString;
        }
        public string StringForForPrint()
        {
            string result;
            result = _caption + " " + _suffusion + " " + _color + "\r\n" + concatDimsForPrint();
            return result;
        }
    }
    public struct DimensionsA
    {
        public DimensionsA(int width, int height, int quantity)
        {
            _width = width;
            _height = height;
            _quantity = quantity;
        }
        public int _width;
        public int _height;
        public int _quantity;
        public int SquareMM()
        {
            return (_width * _height * _quantity);
        }
        public double Square()
        {
            return (_width * _height * _quantity)/1000000;
        }
        public override string ToString()
        {
            return Square().ToString();
        }
    }
    public class Contact
    {
        public Contact(int idConact)
        {
            _idContact = idConact;
        }
        private  int _idContact;
        public int IdContact
        {
            get { return _idContact; }
            set { _idContact = value; }
        }
        private string _note;
        public string Note
        {
            get { return _note.Trim(); }
            set { _note = value; }
        }
        private int _parentId;
        public int ParentId
        {
            get { return _parentId; }
            set { _parentId = value; }
        }

    }
        
    public class Person: Contact
    {
        public Person(int idContact)
            : base(idContact)
        { }
        private string _name;
        public string Name
        {
            get { return _name.Trim(); }
            set { _name = value; }
        }
        private List<Person> _person = new List<Person>();
        public List<Person> PersonArr
        {
            get { return _person; }
            set { _person = value; }
        }
    }
    
    public class Firm : Contact
    {
        public Firm(int idContact)
            : base(idContact)
        { }
        private string captionFirm;
        public string CaptionFirm
        {
            get { return captionFirm; }
            set { captionFirm = value; }
        }
    }
    public class User: IComparable
    {
        public User()
        { }
        public User(int idUser)
        {
            _idUser = idUser;
        }
        private int _idUser;
        public int IdUser
        {
            get { return _idUser; }
            set { _idUser = value; }
        }
        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        private string _sName;
        public string SName
        {
            get { return _sName; }
            set { _sName = value; }
        }
        private string _tName;
        public string TName
        {
            get { return _tName; }
            set { _tName = value; }
        }
        private string _proffesionalLevel;
        public string ProffesionalLevel
        {
            get { return _proffesionalLevel; }
            set { _proffesionalLevel = value; }
        }
        private string _login;
        public string Login
        {
            get { return _login; }
            set { _login = value; }
        }
        public string UserShortName()
        { 
            string shortName = string.Empty;
            shortName = _sName+" "+_name.Substring(0,1)+". "+_tName.Substring(0,1)+".";
            return shortName;
        }
        public override string ToString()
        {
            return UserShortName();
        }

        int IComparable.CompareTo(object o)
        {
            User user = (o as User);
            if (this._idUser > user._idUser)
                return 1;
            if (this._idUser < user._idUser)
                return -1;
            else
                return 0;
        }

    }
    public class Specification
    {
        public Specification(int idSpecifications)
        {
            _idSpecifications = idSpecifications;
        }
        public Specification(int idSpecification, int numberSpecification, DateTime dateDischarge)
        {
            _idSpecifications = idSpecification;
            _numberSpecification = numberSpecification;
            _dateDischarge = dateDischarge;
        }
        private int _idSpecifications;
        public int IdSpecifications
        {
            get { return _idSpecifications; }
            set { _idSpecifications = value; }
        }
        private DateTime _dateDischarge;
        public DateTime DateDischarge
        {
            get { return _dateDischarge; }
            set { _dateDischarge = value; }
        }
        private int _numberSpecification;
        public int NumberSpecification
        {
            get { return _numberSpecification; }
            set { _numberSpecification = value; }
        }
        public override string ToString()
        {
            return _numberSpecification.ToString() + " " + _dateDischarge.ToShortDateString();
        }

    }
    
}
